@extends('layouts.header')
@section('title','短信购买记录')
@section('content')
    <nav class="breadcrumb">
        {{--<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基础信息 <span class="c-gray en">&gt;</span> 微信通知管理--}}
        <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
           title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray">
            <span class="">
                <a href="javascript:;" class="btn btn-primary radius" onclick="layer_show('添加','add','','',true)"><i class="Hui-iconfont">&#xe732;</i> 添加 </a>
            </span>
        </div>
        <div class="mt-10">
            <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
                <thead>
                <tr class="text-c">
                    <th>ID</th>
                    <th>申请人</th>
                    <th>内容</th>
                    <th>申请时间</th>
                    {{--                    <th>默认</th>--}}
                    <th>审核状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data['list'] as $item)
                    <tr class="text-c">
                        <td>{{$item->id}}</td>
                        <td>{{$item->realname}}</td>
                        <td>{{$item->name}}</td>
                        <td>{{$item->ctime}}</td>
                        {{--                        <td>{{$item->is_def == 1 ? '是' : '否'}}</td>--}}
                        <td class="status">{{$item->status == 0 ? '审核中' : ($item->status == 1 ? '通过' : '驳回')}}</td>
                        <td class="text-l">
                            <a class="btn btn-primary radius size-MINI mt-5" onclick="del('{{$item->id}}')">删除</a>
                            <a class="btn btn-primary radius size-MINI mt-5" onclick="detail('{{$item->id}}',this)">审核详情</a>
                            @if($item->status == 2)
                                <a class="btn btn-primary radius size-MINI mt-5 todef" onclick="layer_show('修改','edit/{{$item->id}}')">修改</a>
                            @endif
                            @if($item->status == 1)
                                <a class=" @if($item->is_def == 1) hidden btn @else btn @endif btn-primary radius size-MINI mt-5 todef" onclick="def('{{$item->id}}',this)">设为默认</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>


    <script type="text/javascript">
        var table;
        $(function () {
            $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
            table = $('#datatable').DataTable({
                //order: [[ 6, 'desc' ]],//默认第几个排序
                ordering: false, // 是否排序
                // "deferRender": true,//延迟渲染速度
            });
        });

        /*删除*/
        function del(id) {
            layer.confirm('确认要删除吗？', {title: '询问', icon: 3}, function (index) {
                ajax('get', 'del/' + id, {}, delback);
            });

            function delback(res) {
                layer.msg(res.msg, {icon: res.code, time: 2000});
                if (res.code == 1) {
                    location.replace(location.href);
                }
            }
        }

        /*设为默认*/
        function def(id, obj) {
            layer.confirm('确认要设为短信发送默认签名吗？', {title: '询问', icon: 3}, function (index) {
                ajax('get', 'def/' + id, {}, defback);
            });

            function defback(res) {
                layer.msg(res.msg, {icon: res.code, time: 2000});
                if (res.code == 1) {
                    $(".todef").removeClass("hidden");
                    $(obj).addClass('hidden');
                }
            }
        }

        /*审核详情*/
        function detail(id, obj) {
            ajax('get', 'detail/' + id, {}, detailback);

            function detailback(res) {
                if (res.code === 1) {
                    let SignStatus = res.data.SignStatus, status = (SignStatus == 1 ? '通过' : (SignStatus == 0 ? '审核中' : '驳回'));
                    $(obj).closest('tr').find('td.status').text(status);
                    var str = '<form class="form form-horizontal"><div class="ml-10 mt-20">' +
                        '<div class="row cl"><label class="form-label col-xs-2">短信签名:</label><div class="formControls col-xs-10">' + res.data.SignName + '</div></div>' +
                        '<div class="row cl"><label class="form-label col-xs-2">创建日期和时间:</label><div class="formControls col-xs-10">' + res.data.CreateDate + '</div></div>' +
                        '<div class="row cl">' +
                        '<label class="form-label col-xs-2">审核状态:</label><div class="formControls col-xs-10">' + status + '</div> ';
                    str += ' </div>' +
                        '<div class="row cl"><label class="form-label col-xs-2">审核备注:</label><div class="formControls col-xs-10">' + res.data.Reason + '</div></div>' +
                        '</form>';
                    layer.open({
                        type: 1,
                        area: ['auto', 'auto'],
                        content: str,
                        end:function () {
                            location.replace(location.href);
                        }
                    });
                }
            }
        }
    </script>
@endsection
